#include<bits/stdc++.h>
using namespace std;
int T,n,a[200005],ans=-100;
void dfs(int id,int ass,int lr,int lb){
    //cout<<"id:"<<id<<" as"<<ass<<endl;
    if(id==n+1){
        ans=max(ans,ass);
        return;
    }
    //paint red
    if(a[id]==a[lr]){
        dfs(id+1,ass+a[id],id,lb);
    }else if(a[id]==a[lb]){
        dfs(id+1,ass+a[id],lr,id);
    }else{
        dfs(id+1,ass,id,lb);
        dfs(id+1,ass,lr,id);
    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        ans=-100;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        if(a[1]==a[2]){
            //1 red 2 blue
            dfs(3,a[1],2,0);
        }else{
            dfs(3,0,1,2);
        }
        cout<<ans<<endl;
    }

    return 0;
}
